home *** CD-ROM | disk | FTP | other *** search
- #include "bm.h"
- #include "extern.h"
- #include <stdlib.h> /* N2 03-17-91 */
- #include "proto.h" /* N2 04-05-91 */
-
- int Search(char Pattern[],int PatLen,char *EndBuff,int Skip1[],int Skip2[],
- struct PattDesc *Desc)
- {
- char *k, /* indexes text */
- *j, /* indexes Pattern */
- *PatBegin; /* register pointing to char
- before beginning of Pattern */
- int Skip; /* skip distance */
- char *PatEnd,
- *BuffEnd; /* pointers to last char in Pattern and Buffer */
- BuffEnd = EndBuff;
- PatBegin = Pattern - 1;
- PatEnd = Pattern + PatLen - 1;
-
- k = Desc->Start;
- Skip = PatLen-1;
- while ( Skip <= (BuffEnd - k) )
- {
- j = PatEnd;
- k = k + Skip;
- if (mFlag)
- {
- while ((j > PatBegin) && (*j == toupper(*k)))
- {
- --j; --k;
- } /* while */
- }
- else
- {
- while (j > PatBegin && *j == *k)
- {
- --j; --k;
- } /* while */
- }
- if (j < Pattern)
- {
- /* found it. Start next search just after the pattern */
- Desc -> Start = k + 1 + Desc->PatLen;
- return(1);
- } /* if */
- if (mFlag)
- {
- Skip = max(Skip1[toupper(*(unsigned char *)k)],Skip2[j-Pattern]);
- }
- else
- {
- Skip = max(Skip1[*(unsigned char *)k],Skip2[j-Pattern]);
- }
- } /* while */
- Desc->Start = k;
- return(0);
- } /* Search */
-